package com.trkj.focusonzhuzhou.user.adapter;

import java.util.ArrayList;
import java.util.List;

import com.trkj.focusonzhuzhou.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CollectingNewsAdapter extends BaseAdapter {

	private List<News> list = new ArrayList<News>();
	private Context context;
	
	
	public CollectingNewsAdapter() {
		super();
	}

	public CollectingNewsAdapter(List<News> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		
		if(convertView == null){
			
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).
					inflate(R.layout.my_collection_items, null);
			
			viewHolder.tvTitle = (TextView) convertView.
					findViewById(R.id.tv_collect_news_title);
			viewHolder.tvDate = (TextView) convertView.
					findViewById(R.id.tv_collecting_date);
			viewHolder.tvContent = (TextView) convertView.
					findViewById(R.id.tv_content_comment);
			viewHolder.tvNumber = (TextView) convertView.
					findViewById(R.id.tv_content_number);
			
			News news = list.get(position);
			viewHolder.tvTitle.setText(news.getTitle());
			viewHolder.tvDate.setText(news.getCollectingDate());
			viewHolder.tvContent.setText(news.getContent());
			viewHolder.tvNumber.setText(news.getCommentNumber() + "");
			
			convertView.setTag(viewHolder);
			
		}else{
			
			viewHolder = (ViewHolder) convertView.getTag();
			
		}
		
		return convertView;
	}

	
	private class ViewHolder{
		
		private TextView tvTitle;
		private TextView tvContent;
		private TextView tvDate;
		private TextView tvNumber;
		
	}
}
